<?php

namespace Admin\Controller;

use Think\Controller;

class UserCenterController extends CommonController
{

    public function user_center()
    {

        $where['a.admin_name'] = array('eq', $_SESSION['name']);
        $feedback = M('user_message', '', 'KEFU')->join('a join dxd_kefu.user_feedback c on a.uf_id=c.id')->join('dxd_user.user b on c.vid=b.vid')->where($where)->group('c.vid')->field('c.vid')->select();
        $count = count($feedback);
        $tol = ceil($count / 10);
        $this->assign(array('total' => $tol));
        $this->display();

    }

    /**
     * 用户认证基础信息
     */
    public function user_info()
    {
        $vid = I('get.vid');
        $user = M('user', '', 'USER')->where(['vid' => $vid])->field('alipay_verify,work_verify,waitdays,vid,mobile,truename,id_card,icon,address,status,waitdays,statustype,province,city,residence_time,
        ismarry,degree,checkstatus,work_cert,cert_status,zhima_verify,contact_verify,cert_time,ctime,sex,taobao_verify,
        usermsg_verify,mobile_verify,shebao_verify,jd_verify,credit_verify,check_type,money,quota,balance,freeze_balance')->find();

        //支付宝认证1未认证，2认证中，3已认证，4认证失败
        switch ($user['alipay_verify']) {
            case 1:
                $user['alipay_verify'] = '未认证';
                break;
            case 2:
                $user['alipay_verify'] = '认证中';
                break;
            case 3:
                $user['alipay_verify'] = '已认证';
                break;
            case 4:
                $user['alipay_verify'] = '认证失败';
                break;
        }

        switch ($user['work_verify']) {
            case 1:
                $user['work_verify'] = '认证';
                break;
            case 2:
                $user['work_verify'] = '待修改';
                break;
            case 0:
                $user['work_verify'] = '未认证';
                break;
        }

        if ($user['waitdays'] != 0) {
            $user['waitdays'] = round(($user['waitdays'] - time()) / (3600 * 24));
        }

        if ($user['waitdays'] <= 0) {
            $user['waitdays'] = 0;
        }

        $user['mobilefirm'] = M('user_login', '', 'USER')->where(['vid' => $vid])->getfield('mobilefirm');
        //拉黑用户的 拉黑原因
        if ($user['status'] == '3') {
            $user['user_status'] = '3';
            $user['black_reason'] = M('user_blacklist', '', 'URGE')->where(['vid' => $user['vid'], 'status' => '1'])->getfield('content');
        } else {
            $user['user_status'] = $user['status'];
            $user['black_reason'] = '';
        }

        //用户标识欺诈标识，1正常，2黑户
        $mark = M('user_login', '', 'USER')->where(['vid' => $user['vid']])->getfield('mark');
        if ($mark == 1) {
            $user['mark'] = '正常';
        } else if ($mark == 2) {
            $user['mark'] = '黑户';
        }

        //运营商认证时间 ZX_R
        $time = M('mobile_basicinfo', '', 'ZX_R')->where(['vid' => $user['vid']])->field('register_time')->find();
        $cert_time = $user['cert_time'];

        if ($time['register_time'] <= 0) {
            $user['register_time'] = '';
        } else {
//            $user['register_time']=1;
            $user['register_time'] = date('Y-m-d H:i', $time['register_time']);
        }

        if (empty($user['cert_time'])) {
            $user['cert_time'] = '';
        } else {
            $user['cert_time'] = date('Y-m-d H:i', $user['cert_time']);
        }

        $user['ctime'] = date('Y-m-d H:i', $user['ctime']);

        //基础认证，1未认证，2已通过，3未通过4.认证中,5审核中
        if ($user['cert_status'] == 2) {
            $user['cert_status'] = '通过';
        } else if ($user['cert_status'] == 1) {
            $user['cert_status'] = '未认证';
        } else if ($user['cert_status'] == 3) {
            $user['cert_status'] = '未通过';
        } else if ($user['cert_status'] == 4) {
            $user['cert_status'] = '认证中';
        } else if ($user['cert_status'] == 5) {
            $user['cert_status'] = '审核中';
        }

        if ($user['sex'] == 1) {//用户性别
            $user['sex'] = '男';
        } else if ($user['sex'] == 2) {
            $user['sex'] = '女';
        } else if ($user['sex'] == 0) {
            $user['sex'] = '未知';
        }

        if ($user['status'] == 1) {//当前状态
            $user['status'] = '正常';
        } else if ($user['status'] == 2) {
            $user['status'] = '锁定';
        } else if ($user['status'] == 3) {
            $user['status'] = '黑名单';
        }

        if ($user['check_type'] == 1) {//操作类型
            $user['check_type'] = '无操作';
        } else if ($user['check_type'] == 2) {
            $user['check_type'] = '机器审核';
        } else if ($user['check_type'] == 3) {
            $user['check_type'] = '人工审核';
        }

        if ($user['statustype'] == 1) {//审核类型
            $user['statustype'] = '信息认证审核';
        } else if ($user['statustype'] == 2) {
            $user['statustype'] = '贷前审核';
        } else {
            $user['statustype'] = '无';
        }

        if ($user['checkstatus'] == 1) {//当前审核状态
            $user['checkstatus'] = '待审核';
        } else if ($user['checkstatus'] == 2) {
            $user['checkstatus'] = '正在审核状态';
        } else if ($user['checkstatus'] == 3) {
            $user['checkstatus'] = '完成审核';
        }

        if ($user['work_cert'] == 1) {//工作认证
            $user['work_cert'] = '未认证';
        } else if ($user['work_cert'] == 2) {
            $user['work_cert'] = '已认证';
        }


        if ($user['zhima_verify'] == 1) {//芝麻认证
            $user['zhima_verify'] = '通过';
        } else if ($user['zhima_verify'] == 0) {
            $user['zhima_verify'] = '未通过';
        }

        if ($user['contact_verify'] == 1) {//紧急联系人
            $user['contact_verify'] = '已完成';
        } else if ($user['contact_verify'] == 0) {
            $user['contact_verify'] = '未完成';
        }

        if ($user['usermsg_verify'] == 1) {//用户信息
            $user['usermsg_verify'] = '已完成';
        } else if ($user['usermsg_verify'] == 0) {
            $user['usermsg_verify'] = '未完成';
        }

        if ($user['mobile_verify'] == 1) {//运营商认证
            $user['mobile_verify'] = '未认证';
        } else if ($user['mobile_verify'] == 2) {
            $user['mobile_verify'] = '认证中';
        } else if ($user['mobile_verify'] == 3) {
            $user['mobile_verify'] = '认证成功';
        } else if ($user['mobile_verify'] == 4) {
            $user['mobile_verify'] = '认证失败';
        }
        switch ($user['taobao_verify']) {
            case 1:
                $user['taobao_verify'] = '未认证';
                break;
            case 2:
                $user['taobao_verify'] = '认证中';
                break;
            case 3:
                $user['taobao_verify'] = '认证成功';
                break;
            case 4:
                $user['taobao_verify'] = '认证失败';
                break;
        }

        if ($user['shebao_verify'] == 1) {//社保认证
            $user['shebao_verify'] = '未认证';
        } else if ($user['shebao_verify'] == 2) {
            $user['shebao_verify'] = '认证中';
        } else if ($user['shebao_verify'] == 3) {
            $user['shebao_verify'] = '认证成功';
        } else if ($user['shebao_verify'] == 4) {
            $user['shebao_verify'] = '认证失败';
        }

        if ($user['jd_verify'] == 1) {//社保认证
            $user['jd_verify'] = '未认证';
        } else if ($user['jd_verify'] == 2) {
            $user['jd_verify'] = '认证中';
        } else if ($user['jd_verify'] == 3) {
            $user['jd_verify'] = '认证成功';
        } else if ($user['jd_verify'] == 4) {
            $user['jd_verify'] = '认证失败';
        }


        if ($user['credit_verify'] == 1) {//信用卡认证
            $user['credit_verify'] = '未认证';
        } else if ($user['credit_verify'] == 2) {
            $user['credit_verify'] = '认证中';
        } else if ($user['credit_verify'] == 3) {
            $user['credit_verify'] = '认证成功';
        } else if ($user['credit_verify'] == 4) {
            $user['credit_verify'] = '认证失败';
        }

        $login = M('user_login', '', 'USER')->where(['vid' => $user['vid']])->field('mobilefirm,register_ip')->find();
        $user['mobilefirm'] = $login['mobilefirm'];
        $user['register_ip'] = $login['register_ip'];

        //工作认证详情
        $work = M('user_woke_verify', '', 'USER')->where(['vid' => $vid])->field('work_mobile,work_address,work_position,work_company,img_one,img_thr,img_two,monthly_income,ctime')->find();

        $this->assign(array(
            'user' => $user,
            'work' => $work,
            'vid' => $user['vid'],
            'cert_time' => $cert_time,
        ));

        $this->display();
    }

    /**
     * 用户中心列表
     */
    public function user_list()
    {
        //1 我的客户 2已借贷客户 3未借贷 4 逾期 5 坏账
        $type = I('type');
        $n = I('page', 1);
        $num = 10;
        $page = ($n - 1) * $num;
        $value = I('value');
        $search = I('search');
        $field = "b.truename,b.mobile,b.sex,b.ctime,b.id as user_id,b.vid";
        $where = [];
        //搜索
        if (!empty($value) && !empty($search)) {
            if ($value == 1) {  //姓名搜索
                $where['b.truename'] = array('eq', $search);
            } else if ($value == 2) {//号码搜索
                $where['b.mobile'] = array('eq', $search);
            } else if ($value == 3) {//ID搜索
                $where['b.id'] = array('eq', $search);
            }
        }
        switch ($type) {
            case 1:
                $where['a.admin_name'] = array('eq', $_SESSION['name']);
                $feedback = M('user_message', '', 'KEFU')->join('a join dxd_kefu.user_feedback c on a.uf_id=c.id')->join('dxd_user.user b on c.vid=b.vid')->where($where)->group('c.vid')->field('c.vid')->select();
                $count = count($feedback);
                $data = M('user_message', '', 'KEFU')->join('a join dxd_kefu.user_feedback c on a.uf_id=c.id')->join('dxd_user.user b on c.vid=b.vid')->where($where)->field($field)->group('c.vid')->order('b.id desc')->limit($page, $num)->select();
                break;
            case 2:
                $borrow = M('user_borrow', '', 'CAIWU')->join(' a join dxd_user.user b on a.vid=b.vid')->group('a.vid')->field('a.vid')->select();
                $count = count($borrow);
                $data = M('user_borrow', '', 'CAIWU')->join(' a join dxd_user.user b on a.vid=b.vid')->group('a.vid')->order('b.ctime desc')->field($field)->limit($page, $num)->select();
                break;
            case 3:
                $count = M('user', '', 'USER')->query('SELECT COUNT(a.vid) as num from dxd_user.`user` a LEFT JOIN (SELECT vid FROM dxd_caiwu.user_borrow GROUP BY vid) b on a.vid=b.vid WHERE b.vid is null');
                $count = $count[0]['num'];
                $sql = 'SELECT a.truename,a.vid,a.mobile,a.sex,a.ctime,a.id as user_id from dxd_user.`user` a LEFT JOIN (SELECT vid FROM dxd_caiwu.user_borrow GROUP BY vid) b on a.vid=b.vid WHERE b.vid is null order by a.id desc LIMIT ' . $page . ',' . $num;
                $data = M('user', '', 'USER')->query($sql);
                break;
            case 4:
                $borrow = M('user_overdue', '', 'URGE')->join(' a join dxd_user.user b on a.vid=b.vid')->group('a.vid')->field('a.vid')->select();
                $count = count($borrow);
                $data = M('user_overdue', '', 'URGE')->join(' a join dxd_user.user b on a.vid=b.vid')->group('a.vid')->order('b.ctime desc')->field($field)->limit($page, $num)->select();
                break;
            case 5://逾期超过90天为坏账用户
                $where['a.merchant_num'] = array('eq', 'dh_kefu');
                $where['a.overdue_day'] = array('gt', 90);
                $where['a.status'] = array('eq', 1);
                $borrow = M('user_overdue', '', 'URGE')->join(' a join dxd_user.user b on a.vid=b.vid')->where($where)->group('a.vid')->field('a.vid')->select();
                $count = count($borrow);
                $data = M('user_overdue', '', 'URGE')->join(' a join dxd_user.user b on a.vid=b.vid')->where($where)->group('a.vid')->order('b.ctime desc')->field($field)->limit($page, $num)->select();
                break;

            default :
                $where = [];
                if (!empty($value) && !empty($search)) {
                    if ($value == 1) {  //姓名搜索
                        $where['truename'] = array('eq', $search);
                    } else if ($value == 2) {//号码搜索
                        $where['mobile'] = array('eq', $search);
                    } else if ($value == 3) {//号码搜索
                        $where['id'] = array('eq', $search);
                    }
                }
                $data = M('user', '', 'USER')->where($where)->field('truename,mobile,sex,ctime,id as user_id')->select();
                break;
        }

        foreach ($data as $k => $v) {
            if (empty($v['truename'])) {
                $data[$k]['truename'] = '----';
            }
            $data[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
            if ($v['sex'] == 1) {
                $data[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $data[$k]['sex'] = '女';
            } else {
                $data[$k]['sex'] = '未知';
            }
            //隐藏手机号
            $first = substr($v['mobile'], 0, 3);
            $end = substr($v['mobile'], 7, 4);
            $data[$k]['user_mobile'] = $first . '*****' . $end;

            //最后沟通时间
            $contact_time = M('user_feedback', '', 'KEFU')->where(['vid' => $v['vid']])->order('id desc')->field('upd_time')->limit(1)->find();
            if ($contact_time['upd_time'] > 0) {
                $data[$k]['upd_time'] = date('Y-m-d H:i:s', $contact_time['upd_time']);
            } else {
                $data[$k]['upd_time'] = "--:--:--";
            }

        }
        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(['code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data]);

    }

    public function borrow_record()
    {

        $this->display();
    }

    /**
     * 通话记录视图
     */
    public function call_record()
    {
        $this->display();
    }

    /**
     * 来电通话记录
     */
    public function call_in_record()
    {
        $n = I('page');
        $num = 10;
        $page = ($n - 1) * $num;
        $vid = I('vid');
        $count = M('call_info', '', 'KEFU')->where(['vid' => $vid, 'calltype' => 2])->count();
        $data = M('call_info', '', 'KEFU')->where(['vid' => $vid, 'calltype' => 2])->field('agent,category,id,callsheetid,callno,ring,begin,end,state,province,district,admin,content,voice_url')->order('id desc')->limit($page, $num)->select();
        foreach ($data as $k => $v) {


            if (empty($v['admin'])) {
                $data[$k]['admin'] = '工号' . $v['agent'];
            }
            if (empty($v['content'])) {
                $data[$k]['content'] = "无";
            }
            $data[$k]['ring'] = date('Y-m-d H:i:s', $v['ring']);
            if ($v['ring'] <= 0) {
                $data[$k]['ring'] = '---';
            }
            $data[$k]['begin'] = date('Y-m-d H:i:s', $v['begin']);
            if ($v['begin'] <= 0) {
                $data[$k]['begin'] = '---';
            }
            $data[$k]['end'] = date('Y-m-d H:i:s', $v['end']);
            if ($v['end'] <= 0) {
                $data[$k]['end'] = '---';
            }

            //接听状态：1已接 2（振铃未接听）,3（ivr放弃）,4（排队放弃）,5（黑名单）,6（留言）
            //通话时长
            if ($v['end'] > 0 && $v['begin'] > 0) {
                $get_time = $v['end'] - $v['begin'];
                $min = floor($get_time / 60);
                $second = $get_time - ($min * 60);
                $data[$k]['talk_time'] = $min . '分' . $second;
            } else {
                $data[$k]['talk_time'] = '---';
            }

            switch ($v['state']) {
                case 1:
                    $data[$k]['state'] = '已接';
                    break;
                case 2:
                    $data[$k]['state'] = '振铃未接听';
                    break;
                case 3:
                    $data[$k]['state'] = 'ivr放弃';
                    break;
                case 4:
                    $data[$k]['state'] = '排队放弃';
                    break;
                case 5:
                    $data[$k]['state'] = '黑名单';
                    break;
                case 6:
                    $data[$k]['state'] = '留言';
                    break;
            }

            switch ($v['category']) {
                case '1':
                    $data[$k]['cate'] = '普通';
                    break;
                case '2':
                    $data[$k]['cate'] = '投诉';
                    break;
                case '3':
                    $data[$k]['cate'] = ' 所属项目';
                    break;
                default:
                    $data[$k]['cate'] = '普通';
                    break;
            }
        }
        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(array('code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data));
    }

    /**
     * 去电通话记录
     */
    public function call_out_record()
    {
        $n = I('page');
        $num = 10;
        $page = ($n - 1) * $num;
        $vid = I('vid');
        $count = M('call_info', '', 'KEFU')->where(['vid' => $vid, 'calltype' => 1])->count();
        $data = M('call_info', '', 'KEFU')->where(['vid' => $vid, 'calltype' => 1])->field('id,callsheetid,ring,begin,end,state,admin,content,voice_url')->order('id desc')->limit($page, $num)->select();
        foreach ($data as $k => $v) {
            if (empty($v['admin'])) {
                $data[$k]['admin'] = "无";
            }
            if (empty($v['content'])) {
                $data[$k]['content'] = "无";
            }
            $data[$k]['ring'] = date('Y-m-d H:i:s', $v['ring']);
            if ($v['ring'] <= 0) {
                $data[$k]['ring'] = '---';
            }
            $data[$k]['begin'] = date('Y-m-d H:i:s', $v['begin']);
            if ($v['begin'] <= 0) {
                $data[$k]['begin'] = '---';
            }

            $data[$k]['end'] = date('Y-m-d H:i:s', $v['end']);

            if ($v['end'] <= 0) {
                $data[$k]['end'] = '---';
            }
            //接听状态：1已接 2（振铃未接听）,3（ivr放弃）,4（排队放弃）,5（黑名单）,6（留言）
            //通话时长
            if ($v['end'] > 0 && $v['begin'] > 0) {
                $get_time = $v['end'] - $v['begin'];
                $min = floor($get_time / 60);
                $second = $get_time - ($min * 60);
                $data[$k]['talk_time'] = $min . '分' . $second;
            } else {
                $data[$k]['talk_time'] = '---';
            }

            switch ($v['state']) {
                case 1:
                    $data[$k]['state'] = '已接';
                    break;
                case 2:
                    $data[$k]['state'] = '振铃未接听';
                    break;
                case 3:
                    $data[$k]['state'] = 'ivr放弃';
                    break;
                case 4:
                    $data[$k]['state'] = '排队放弃';
                    break;
                case 5:
                    $data[$k]['state'] = '黑名单';
                    break;
                case 6:
                    $data[$k]['state'] = '留言';
                    break;
            }
        }
        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(array('code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data));
    }

    /**
     * 个人中心借款记录
     */
    public function borrow_record_list()
    {
        $vid = I('vid');
        $n = I('page');
        $count = M('user_borrow', '', 'CAIWU')->join('b join rate a on b.rate_id=a.id')->where(['a.vid' => $vid, 'b.is_success' => 2])->count();
        $num = '10';
        $page = ($n - 1) * $num;
        $data = M('user_borrow', '', 'CAIWU')->join('b join rate a on b.rate_id=a.id')->where(['vid' => $vid, 'b.is_success' => 2])
            ->field('b.borrow_type,b.rate_id,b.borrow_no,b.money,b.fee,b.is_success,b.ctime,b.get_time,b.status,a.type')
            ->order('b.ctime desc')->LIMIT($page, $num)->select();
        foreach ($data as $k => $v) {
            $pay_time = M('user_repayment', '', 'CAIWU')->where(['borrow_no' => $v['borrow_no']])->getfield('repay_time');
            $data[$k]['repay_time'] = date('Y-m-d H:i', $pay_time);
            if ($v['is_success'] == 1) {
                $data[$k]['is_success'] = '打款中';
            } else if ($v['is_success'] == 2) {
                $data[$k]['is_success'] = '成功到账';
            } else if ($v['is_success'] == 3) {
                $data[$k]['is_success'] = '打款失败';
            }
            if ($v['status'] == 1) {
                $data[$k]['status'] = '未还款';
            } else if ($v['status'] == 2) {
                $data[$k]['status'] = '已还款';
            } else if ($v['status'] == 3) {
                $data[$k]['status'] = '已取消借款';
            }
            $data[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
            if ($v['get_time'] > 100) {
                $data[$k]['get_time'] = date('Y-m-d H:i', $v['get_time']);
            } else {
                $data[$k]['get_time'] = '-';
            }

            switch ($v['borrow_type']) {
                case 1:
                    $data[$k]['borrow_type'] = "正常借款";
                    break;
                case 2:
                    $data[$k]['borrow_type'] = "不限额借款";
                    break;
                case 3:
                    $data[$k]['borrow_type'] = "购买旅游产品";
                    break;
                case 4:
                    $data[$k]['borrow_type'] = "退款旅游产品";
                    break;
                case 5:
                    $data[$k]['borrow_type'] = "购买硅谷堂产品";
                    break;
                case 6:
                    $data[$k]['borrow_type'] = "购买聚一场产品";
                    break;
            }
        }
        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(['code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data]);

    }

    /**
     *  还款记录
     */
    public function repayment_record()
    {

        $this->display();
    }

    /**
     * 分期记录
     */
    public function stage_record(){
        $this->display();
    }

    public function stage_record_list(){
        $vid = I('vid');
        $n = I('page');
        $count = M('user_by_stages', '', 'CAIWU')->where(['vid' => $vid, 'status' =>['neq',4]])->count();
        $num = '10';
        $page = ($n - 1) * $num;
        $data= M('user_by_stages', '', 'CAIWU')
            ->where(['vid' => $vid, 'status' =>['neq',4]])
            ->field('id,money,have_repay_money,fq_orderno,stages,status,repay_time,real_time,is_overdue')
            ->limit($page,$num)
            ->order('id desc')
            ->select();
        foreach ($data as $k=>$v){
            switch ($v['status']){
                case 1: $data[$k]['pay_status']='待还款';   break;
                case 2: $data[$k]['pay_status']='还款中';   break;
                case 3: $data[$k]['pay_status']='还款成功';   break;
                case 4: $data[$k]['pay_status']='取消还款';   break;
                default : $data[$k]['pay_status']='未知状态';   break;
            }
            $data[$k]['repay_time']=date('Y-m-d H:i',$v['repay_time']);

            if($v['real_time']){
                $data[$k]['real_time']=date('Y-m-d H:i',$v['real_time']);
            }else{
                $data[$k]['real_time']='--';
            }

//            if($v['is_overdue']=='1'){
//
//            }
        }

        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(['code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data]);
    }

    /**
     * 个人中心还款记录
     */
    public function repayment_record_list()
    {
        $vid = I('vid');
        $n = I('page');
        $num = '10';
        $page = ($n - 1) * $num;
        $user_repayment = M('user_repayment', '', 'CAIWU');
        $count = $user_repayment->where(['vid' => $vid, 'status' => ['neq',5]])->count();

        $data = M('user_repayment', '', 'CAIWU')->where(['vid' => $vid, 'status' => ['neq',5]])->LIMIT($page, $num)->field('borrow_no,repayment_no,repay_money,repay_time,real_time,type,status,rate_id,have_repay_money,renewal_money,fee,is_stages')->order('repay_time desc,real_time desc')->select();
        foreach ($data as $k => $v) {
            $over_status = M('overdue_order', '', 'CAIWU')->where(['repayment_no' => $v['repayment_no']])->getfield('status');

            if ($v['is_success'] == 1) {
                $data[$k]['is_success'] = '打款中';
            } else if ($v['is_success'] == 2) {
                $data[$k]['is_success'] = '成功到账';
            } else if ($v['is_success'] == 3) {
                $data[$k]['is_success'] = '打款失败';
            }

            switch ($v['type']){
                case 1:  $data[$k]['type'] = '主动打款'; break;
                case 2:  $data[$k]['type'] = '自动还款'; break;
                case 3:  $data[$k]['type'] = '主动打款'; break;
                case 4:  $data[$k]['type'] = '支付宝还款'; break;
                case 5:  $data[$k]['type'] = '聚合平台支付还款'; break;
                case 6:  $data[$k]['type'] = '京东自动代扣'; break;
                case 7:  $data[$k]['type'] = '京东主动还款'; break;
                case 8:  $data[$k]['type'] = '批量还款'; break;
                case 9:  $data[$k]['type'] = '隔天易旅游代偿'; break;
                case 10:  $data[$k]['type'] = '当天易旅游代偿'; break;
                case 11:  $data[$k]['type'] = '分期还款'; break;
                case 12:  $data[$k]['type'] = '益倍嘉微信还款'; break;
                case 13:  $data[$k]['type'] = '益倍嘉百度钱包'; break;
                case 14:  $data[$k]['type'] = '易旅游余额代扣'; break;
            }


            if ($v['status'] == 1) {
                $data[$k]['status'] = '待还款';
            } else if ($v['status'] == 2) {
                $data[$k]['status'] = '还款中';
            } else if ($v['status'] == 3) {
                $data[$k]['status'] = '还款成功';
            } else if ($v['status'] == 4) {
                $data[$k]['status'] = '还款失败';
            } else if ($v['status'] == 5) {
                $data[$k]['status'] = '取消还款';
            }

//            $data[$k]['pay_status'] = $v['status'];

            if ($over_status == '1' && $v['is_stages']=='1') {
                $data[$k]['pay_status'] = '1';
            }

            $data[$k]['repay_time'] = date('Y-m-d H:i', $v['repay_time']);
            if ($v['real_time'] > 0) {
                $data[$k]['real_time'] = date('Y-m-d H:i', $v['real_time']);
            } else {
                $data[$k]['real_time'] = '';
            }

            //还款天数
            $num = M('rate', '', 'CAIWU')->where(['id' => $v['rate_id'], 'status' => '1'])->getfield('type');
            $data[$k]['day'] = $num;
        }
        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(['code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data]);

    }

    /**
     * 人工微信支付
     */
    public function wx_pay()
    {
        $vid = I('vid');
        $money = I('money');
        $repayment_no = I('repayment_no');
        $post_data = array(
            'vid' => $vid,
            'money' => $money,
            'orderno' => $repayment_no
        );
        $ret = $this->send_post('http://adm.jyyjrfw.com/External/external_wx_pay', $post_data);
        add_log("调用微信支付");
        $json = json_decode($ret);
        $this->ajax($json->code, $json->result);
    }

    /**
     * 人工微信支付 弹框
     */
    public function wx_pay_view()
    {
        $codeUrl = I('get.url');
        $picurl = I('get.picurl');
        $this->assign(array(
            'url' => $codeUrl,
            'picurl' => $picurl
        ));
        $this->display();
    }

    public function overdue_record()
    {
        $this->display();
    }

    /**
     * 逾期记录
     */
    public function overdue_record_list()
    {
        //逾期记录
        $vid = I('vid');
        $n = I('page');
        $num = '10';
        $page = ($n - 1) * $num;
        $user_overdue = M('user_overdue', '', 'URGE');
        $count = $user_overdue->where(['vid' => $vid])->count();
        $data = $user_overdue->where(['vid' => $vid])->LIMIT($page, $num)
            ->field('id,repayment_no,should_time,overdue_day,overdue_money,overdue_time,reduce_money,status')
            ->order('should_time desc,overdue_time desc')->select();
        foreach ($data as $k => $v) {
            if ($v['status'] == 1) {
                $data[$k]['status'] = '未还款';
            } else if ($v['status'] == 2) {
                $data[$k]['status'] = '已还款';
            } else if ($v['status'] == 3) {
                $data[$k]['status'] = '已续期';
            } else if ($v['status'] == 4) {
                $data[$k]['status'] = '已分期';
            }
            $data[$k]['should_time'] = date('Y-m-d H:i', $v['should_time']);
            if ($v['overdue_time'] == 0) {
                $data[$k]['overdue_time'] = '';
            } else {
                $data[$k]['overdue_time'] = date('Y-m-d H:i', $v['overdue_time']);
            }
        }
        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(['code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data]);
    }

    //罚金信息 弹框界面
    public function user_fine()
    {

        $id = I('get.id');
        $over = M('user_overdue', '', 'URGE')->where(['id' => $id])->field('vid,repayment_no')->find();
        $data = M('overdue_order', '', 'CAIWU')->where(['vid' => $over['vid'], 'repayment_no' => $over['repayment_no']])->field('repay_money,status,repay_time,real_time,type,overdue_no')->select();

        foreach ($data as $k => $v) {
            $data[$k]['repay_time'] = date('Y-m-d H:i', $v['repay_time']);
            if (empty($v['real_time'])) {
                $data[$k]['real_time'] = '-';
            } else {
                $data[$k]['real_time'] = date('Y-m-d H:i', $v['real_time']);
            }

            if ($v['status'] == '1') {
                $data[$k]['status'] = '待缴罚金';
            } else if ($v['status'] == '2') {
                $data[$k]['status'] = '还款中';
            } else if ($v['status'] == '3') {
                $data[$k]['status'] = '已收罚金';
            } else if ($v['status'] == '4') {
                $data[$k]['status'] = '还款失败';
            } else if ($v['status'] == '5') {
                $data[$k]['status'] = '取消还款';
            }

            if ($v['type'] == '1') {
                $data[$k]['type'] = '主动还款';
            } else if ($v['type'] == '2') {
                $data[$k]['type'] = '自动还款';
            } else if ($v['type'] == '3') {
                $data[$k]['type'] = '续借还款';
            } else if ($v['type'] == '4') {
                $data[$k]['type'] = '人工还款';
            } else if ($v['type'] == '5') {
                $data[$k]['type'] = '部分还款';
            } else if ($v['type'] == '6') {
                $data[$k]['type'] = '分期还款';
            }

        }


        $this->assign(array(
            'data' => $data
        ));

        $this->display();
    }

    /**
     * 部分还款记录
     */
    public function part_repayment_record()
    {
        $this->display();
    }

    /**
     * 部分还款记录
     */
    public function part_record_list()
    {
        $vid = I('vid');
        $n = I('page');
        $num = '10';
        $page = ($n - 1) * $num;
        $part_repayment = M('part_repayment', '', 'CAIWU');
        $count = $part_repayment->where(['vid' => $vid])->count();
        $field = "repayment_no,money,status,orderno,type,ctime,real_time,pay_type";
        $data = $part_repayment->where(['vid' => $vid])->field($field)->limit($page, $num)->order('ctime desc')->select();
        foreach ($data as $k => $v) {

            $data[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
            if (empty($v['real_time'])) {
                $data[$k]['real_time'] = "---";
            } else {
                $data[$k]['real_time'] = date('Y-m-d H:i', $v['real_time']);
            }

            //  1待支付.2已支付.3删除，4失败
            if ($v['status'] == 1) {
                $data[$k]['status'] = '待支付';
            } else if ($v['status'] == 2) {
                $data[$k]['status'] = '已支付';
            } else if ($v['status'] == 3) {
                $data[$k]['status'] = '删除';
            } else if ($v['status'] == 4) {
                $data[$k]['status'] = '失败';
            }

            if ($v['type'] == 1) {
                $data[$k]['type'] = '正常部分还款';
            } else if ($v['type'] == 2) {
                $data[$k]['type'] = '逾期情况部分还款';
            }
            //1连连支付，2支付宝主动支付，3手动打款，4聚合平台支付，5京东支付，6批量还款，7京东代扣
            switch ($v['pay_type']) {
                case 1:
                    $data[$k]['pay_type'] = '连连支付';
                    break;
                case 2:
                    $data[$k]['pay_type'] = '支付宝主动支付';
                    break;
                case 3:
                    $data[$k]['pay_type'] = '手动打款';
                    break;
                case 4:
                    $data[$k]['pay_type'] = '聚合平台支付';
                    break;
                case 5:
                    $data[$k]['pay_type'] = '京东支付';
                    break;
                case 6:
                    $data[$k]['pay_type'] = '批量还款';
                    break;
                case 7:
                    $data[$k]['pay_type'] = '京东代扣';
                    break;
            }

        }
        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(['code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data]);

    }

    //支付记录

    public function third_pay()
    {

        $this->display();
    }

    //连连支付记录
    public function llzf()
    {
        $vid = I('vid');
        $n = I('page');
        $renewal = M('llzf_record', '', 'CWXX');
        $count = $renewal->where(['vid' => $vid, 'status' => 1])->count();
        $num = '10';
        $page = ($n - 1) * $num;
        $data = $renewal->where(['vid' => $vid, 'status' => 1])->LIMIT($page, $num)
            ->field('llzf_orderno,content,real_money,real_time,orderno,type,money,ctime,status')->order('ctime desc')->select();
        foreach ($data as $k => $v) {

            if ($v['status'] == 1) {
                $data[$k]['status'] = '成功';
            } else if ($v['status'] == 2) {
                $data[$k]['status'] = '失败';
            } else if ($v['status'] == 3) {
                $data[$k]['status'] = '未到';
            }

            switch ($v['type']){
                case 1:     $data[$k]['type'] = '借款'; break;
                case 2:     $data[$k]['type'] = '主动还款'; break;
                case 3:     $data[$k]['type'] = '自动还款'; break;
                case 4:     $data[$k]['type'] = '续期'; break;
                case 5:     $data[$k]['type'] = '人工打款'; break;
                case 6:     $data[$k]['type'] = '用户提现'; break;
                case 7:     $data[$k]['type'] = '加盟费'; break;
                case 8:     $data[$k]['type'] = '部分还款'; break;
                case 9:     $data[$k]['type'] = '渠道商提现'; break;
                case 10:     $data[$k]['type'] = '批量还款'; break;
                case 11:     $data[$k]['type'] = '分期还款'; break;
            }

            $data[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
            if ($v['real_time'] > 0) {
                $data[$k]['real_time'] = date('Y-m-d H:i', $v['real_time']);
            } else {
                $data[$k]['real_time'] = '-';
            }
        }
        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(['code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data]);
    }

    //聚合支付记录
    public function juhe()
    {
        $vid = I('vid');
        $n = I('page');
        $jh_record = M('jh_record', '', 'CWXX');
        $count = $jh_record->where(['vid' => $vid, 'status' => 1])->count();
        $num = '10';
        $page = ($n - 1) * $num;
        $data = $jh_record->where(['vid' => $vid, 'status' => 1])->LIMIT($page, $num)
            ->field('jh_orderno,orderno,type,real_money,ctime,status,content')->order('ctime desc')->select();
        foreach ($data as $k => $v) {

            if ($v['status'] == 1) {
                $data[$k]['status'] = '成功';
            } else if ($v['status'] == 2) {
                $data[$k]['status'] = '失败';
            } else if ($v['status'] == 3) {
                $data[$k]['status'] = '未到';
            }

            if ($v['type'] == 1) {
                $data[$k]['type'] = '部分还款';
            } else if ($v['type'] == 2) {
                $data[$k]['type'] = '主动还款';
            } else if ($v['type'] == 3) {
                $data[$k]['type'] = '续期';
            } else if ($v['type'] == 4) {
                $data[$k]['type'] = '加盟费';
            }
            $data[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
        }
        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(['code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data]);
    }

    //京东支付记录
    public function jd()
    {
        $vid = I('vid');
        $n = I('page');
        $jh_record = M('jd_record', '', 'CWXX');
        $count = $jh_record->where(['vid' => $vid, 'status' => 1])->count();
        $num = '10';
        $page = ($n - 1) * $num;
        $data = $jh_record->where(['vid' => $vid, 'status' => 1])->LIMIT($page, $num)
            ->field('jd_orderno,orderno,type,real_money,money,ctime,status,content')->order('ctime desc')->select();
        foreach ($data as $k => $v) {

            if ($v['status'] == 1) {
                $data[$k]['status'] = '成功';
            } else if ($v['status'] == 2) {
                $data[$k]['status'] = '失败';
            } else if ($v['status'] == 3) {
                $data[$k]['status'] = '未到';
            }
//1、部分还款，2主动还款，3主动续期，4加盟费,5自动续借，6还款代扣，7罚金代扣

            switch ($v['type']){
                case 1:     $data[$k]['type'] = '部分还款'; break;
                case 2:     $data[$k]['type'] = '主动还款'; break;
                case 3:     $data[$k]['type'] = '主动续期'; break;
                case 4:     $data[$k]['type'] = '加盟费'; break;
                case 5:     $data[$k]['type'] = '自动续借'; break;
                case 6:     $data[$k]['type'] = '还款代扣'; break;
                case 7:     $data[$k]['type'] = '罚金代扣'; break;
                case 8:     $data[$k]['type'] = '分期还款'; break;
                case 9:     $data[$k]['type'] = '分期代扣'; break;
            }
            $data[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
        }

        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(['code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data]);
    }

    /*
     * 支付宝支付记录
     ***/
    public function zhifubao()
    {
        $vid = i('vid');
        $n = i('page');
        $renewal = M('alipay_record', '', 'CWXX');
        $count = $renewal->where(['vid' => $vid, 'status' => 1])->count();
        $num = '10';
        $page = ($n - 1) * $num;

        $data = $renewal->where(['vid' => $vid, 'status' => 1])->LIMIT($page, $num)
            ->field('alipay_orderno,orderno,type,money,ctime,status,content')->order('ctime desc')->select();

        foreach ($data as $k => $v) {
            if ($v['status'] == 1) {
                $data[$k]['status'] = '成功';
            } else if ($v['status'] == 2) {
                $data[$k]['status'] = '失败';
            } else if ($v['status'] == 3) {
                $data[$k]['status'] = '未到';
            }

            if ($v['type'] == 1) {
                $data[$k]['type'] = '部分还款';
            } else if ($v['type'] == 2) {
                $data[$k]['type'] = '主动还款';
            } else if ($v['type'] == 3) {
                $data[$k]['type'] = '续期';
            } else if ($v['type'] == 4) {
                $data[$k]['type'] = '加盟费';
            }
            $data[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
        }
        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(['code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data]);
    }

    public function overdue_fine()
    {
        $this->display();
    }

    /*
     * 逾期罚金减免记录
     ***/
    public function overdue_fine_record()
    {
        $vid = I('vid');
        $n = I('page');
        $fine_modify = M('fine_modify_apply', '', 'URGE');
        $repayment = M('user_repayment', '', 'CAIWU');
        $count = $fine_modify->where(['vid' => $vid])->count();
        $num = '10';
        $page = ($n - 1) * $num;
        $data = $fine_modify->join("a join dxd_caiwu.user_repayment b on a.repayment_no=b.repayment_no and b.vid='" . $vid . "'")->field('a.repayment_no,a.reduce_money,a.reason,a.ctime,a.urge_admin,a.status')->limit($page, $num)->select();
        foreach ($data as $k => $v) {
            if ($v['status'] == 1) {
                $data[$k]['status'] = '待审核';
            } else if ($v['status'] == 2) {
                $data[$k]['status'] = '审核通过';
            } else if ($v['status'] == 3) {
                $data[$k]['status'] = '驳回';
            } else if ($v['status'] == 4) {
                $data[$k]['status'] = '已修改';
            }
            $data[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
        }
        $count = intval($count);
        $tol = ceil($count / $num);
        $this->ajaxReturn(['code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data]);
    }


    public function feedback_online()
    {
        $vid = I('vid');
        $n = I('page', 1);
        $num = 10;
        $page = ($n - 1) * $num;
        $feedbackModel = M('user_feedback', '', 'KEFU_R');
        $where['b.vid'] = $vid;
        $count = $feedbackModel->join('b join dxd_user.user a on b.mobile=a.mobile')->where($where)->count();
        $field = 'b.content,b.id,b.mobile,b.ctime,b.status,b.type,b.upd_time,b.vid,a.truename as username, a.id as user_id';
        $data = $feedbackModel->join('b join dxd_user.user a on b.mobile=a.mobile')->where($where)->LIMIT($page, $num)->field($field)->order('b.ctime desc,b.status asc,b.id desc')->select();
        foreach ($data as $k => $v) {
            $data[$k]['back_num'] = M('user_message', '', 'KEFU')->where(['uf_id' => $v['id'], 'vid' => '0'])->count();
            $user_message = M('user_message', '', 'KEFU')->where(['uf_id' => $v['id'], 'vid' => '0'])->field('ctime')->order('ctime desc')->find();
            if (!empty($user_message['ctime'])) {//最近回复时间
                $data[$k]['back_time'] = date('Y-m-d H:i:s', $user_message['ctime']);
            } else {
                $data[$k]['back_time'] = "--:--:--";
            }
            //回复状态
            switch ($v['status']) {
                case 1:
                    $data[$k]['status'] = '未回复';
                    break;
                case 2:
                    $data[$k]['status'] = '已回复';
                    break;
                case 3:
                    $data[$k]['status'] = '完成';
                    break;
            }
            if (empty($v['username'])) {
                $data[$k]['username'] = "----";
            }
            //回复方式
            if ($v['type'] == '1') {
                $data[$k]['type'] = '短信反馈';
            } else if ($v['type'] == '2') {
                $data[$k]['type'] = '电话反馈';
            }
            $data[$k]['ctime'] = date('Y-m-d H:i:s', $v['ctime']);
        }
        $tol = ceil($count / $num);//页数
        $count = intval($count);
        $this->assign(array('vid' => $vid, 'page' => $page, 'code' => '1001', 'tol' => $tol, 'count' => $count, 'data' => $data));
        $this->display();

    }

    //用户调查列表
    public function antiList_record()
    {
        $vid = I('vid');
        $where['b.vid'] = $vid;
        $count = M('user_artificial_check', '', 'KEFU_R')->join('b join dxd_user.user a on b.vid=a.vid')->where($where)->count();
        $field = 'a.truename as name,a.mobile,a.sex,b.status,a.cert_time,a.vid,c.name as admin_name,a.id';
        $user = M('user_artificial_check', '', 'KEFU_R')->join('b join dxd_user.user a on b.vid=a.vid')->join('dxd_kefu.admin c on b.out_kf_id=c.id')->where($where)->field($field)->select();

        //因为换了一张表，之前的数据还有保留
        if (empty($user)) {
            $count = M('anti_check_user', '', 'KEFU_R')->join('b join dxd_user.user a on b.vid=a.vid')->where($where)->count();
            $field = 'a.truename as name,a.mobile,a.sex,b.status,a.cert_time,a.vid,c.name as admin_name,a.id';
            $user = M('anti_check_user', '', 'KEFU_R')->join('b join dxd_user.user a on b.vid=a.vid')->join('dxd_kefu.admin c on b.out_kf_id=c.id')->where($where)->field($field)->select();
        } else {


        }

        foreach ($user as $k => $v) {
            //用户评分
            $user[$k]['logic_score'] = M('user_good_bad', '', 'USER')->where(['vid' => $v['vid']])->getfield('logic_level');
            if ($v['cert_time'] != 0) {
                $user[$k]['cert_time'] = date('Y-m-d H:i', $v['cert_time']);
            } else {
                $user[$k]['cert_time'] = '-';
            }
            if ($v['sex'] == 1) {
                $user[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $user[$k]['sex'] = '女';
            } else {
                $user[$k]['sex'] = '未知';
            }
//'1、反欺诈待调查，2，反欺诈调查中， 3待信审，4信审中，5通过，6 不通过',
            if ($v['status'] == 0) {
                $user[$k]['status'] = '未开始';
            } else if ($v['status'] == 1) {
                $user[$k]['status'] = '待调查';
            } else if ($v['status'] == 2) {
                $user[$k]['status'] = '调查中';
            } else if ($v['status'] == 3) {
                $user[$k]['status'] = '待信审';
            } else if ($v['status'] == 4) {
                $user[$k]['status'] = '信审中';
            } else if ($v['status'] == 5) {
                $user[$k]['status'] = '通过';
            } else if ($v['status'] == 6) {
                $user[$k]['status'] = '审核不通过';
            }
            //隐藏手机号
            $first = substr($v['mobile'], 0, 3);
            $end = substr($v['mobile'], 7, 4);
            $user[$k]['user_mobile'] = $first . '*****' . $end;
        }

        $this->assign(array('vid' => $vid, 'code' => '1001', 'count' => $count, 'data' => $user));
        $this->display();
    }

    //用户调查列表
    public function antiList_record1()
    {

        $vid = I('vid');
        $where['b.vid'] = $vid;
        $count = M('anti_check_user', '', 'KEFU_R')->join('b join dxd_user.user a on b.vid=a.vid')->where($where)->count();
        $field = 'a.truename as name,a.mobile,a.sex,b.status,a.cert_time,a.vid,c.name as admin_name,a.id';
        $user = M('anti_check_user', '', 'KEFU_R')->join('b join dxd_user.user a on b.vid=a.vid')->join('dxd_kefu.admin c on b.out_kf_id=c.id')->where($where)->field($field)->select();

        foreach ($user as $k => $v) {
            //用户评分
            $user[$k]['logic_score'] = M('user_good_bad', '', 'USER')->where(['vid' => $v['vid']])->getfield('logic_level');

            if ($v['cert_time'] != 0) {
                $user[$k]['cert_time'] = date('Y-m-d H:i', $v['cert_time']);
            } else {
                $user[$k]['cert_time'] = '-';
            }

            if ($v['sex'] == 1) {
                $user[$k]['sex'] = '男';
            } else if ($v['sex'] == 2) {
                $user[$k]['sex'] = '女';
            } else {
                $user[$k]['sex'] = '未知';
            }
//0 未开始  7正在调查 1 标记过  2 提交审核待接收  3 审核中 4 审核驳回 5 审核通过  6审核不通过 8 驳回的再次派发
            if ($v['status'] == 0) {
                $user[$k]['status'] = '未开始';
            } else if ($v['status'] == 1) {
                $user[$k]['status'] = '标记过';
            } else if ($v['status'] == 2) {
                $user[$k]['status'] = '提交审核待接收';
            } else if ($v['status'] == 3) {
                $user[$k]['status'] = '审核中';
            } else if ($v['status'] == 4) {
                $user[$k]['status'] = '审核驳回';
            } else if ($v['status'] == 5) {
                $user[$k]['status'] = '审核通过';
            } else if ($v['status'] == 6) {
                $user[$k]['status'] = '审核不通过';
            } else if ($v['status'] == 7) {
                $user[$k]['status'] = '正在调查';
            } else if ($v['status'] == 8) {
                $user[$k]['status'] = '驳回';
            }
            //隐藏手机号
            $first = substr($v['mobile'], 0, 3);
            $end = substr($v['mobile'], 7, 4);
            $user[$k]['user_mobile'] = $first . '*****' . $end;

        }
        $this->assign(array('vid' => $vid, 'code' => '1001', 'count' => $count, 'data' => $user));
        $this->display();
    }

    //催收记录
    public function urge_record()
    {
        $this->display();
    }

    //催收记录
    public function urge_record_list()
    {
        $vid = I('vid');
        $n = I('page', 1);
        $num = 10;
        $page = ($n - 1) * $num;
        $count = M('user_overdue', '', 'URGE')->join('a join dxd_urge.mark b on a.repayment_no=b.repayment_no')->where(['a.vid' => $vid])->count();
        $urge_count = M('user_overdue', '', 'URGE')->join('a join dxd_urge.mark b on a.repayment_no=b.repayment_no')->join('dxd_urge.urge_admin c on b.ua_id=c.id')->limit($page, $num)->where(['a.vid' => $vid])->field('b.repayment_no,b.reason,c.name,b.ctime')->select();
        foreach ($urge_count as $k => $v) {
            $urge_count[$k]['ctime'] = date('Y-m-d H:i', $v['ctime']);
        }
        $tol = ceil($count / $num);//页数
        $count = intval($count);
        $this->ajaxReturn(array('code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $urge_count));
    }

    //工作认证
    public function work_cert()
    {
        $vid = I('vid');
        $data = M('user_woke_verify', '', 'USER')->where(['vid' => $vid])->field('work_mobile,work_address,work_position,work_company,img_one,img_thr,img_two,monthly_income,ctime')->find();

        $this->assign(array(
            'data' => $data
        ));
        $this->display();

    }

    //额度记录
    public function quota_list()
    {
        $vid = I('vid');
        $n = I('page', 1);
        $num = 10;
        $page = ($n - 1) * $num;
        $field = 'content,money,type,admin_name,ctime';
        $count = M('user_quota_record', '', 'CAIWU')->where(['vid' => $vid])->count();
        $data = M('user_quota_record', '', 'CAIWU')->where(['vid' => $vid])->order('id desc')->limit($page, $num)->field($field)->select();
        foreach ($data as $k => $v) {

            $data[$k]['ctime'] = date('Y-m-d H:i:s', $v['ctime']);
            switch ($v['type']) {
                case 1:
                    $data[$k]['type'] = '机器修改';
                    break;
                case 2:
                    $data[$k]['type'] = '人工修改';
                    break;
                case 3:
                    $data[$k]['type'] = '临时提额';
                    break;
                case 4:
                    $data[$k]['type'] = '活动提额';
                    break;
            }
        }
        $tol = ceil($count / $num);//页数
        $count = intval($count);
        $this->ajaxReturn(array('code' => '1001', 'tol' => $tol, 'count' => $count, 'result' => $data));

    }

    /**
     * 发送post请求
     * @param string $url 请求地址
     * @param array $post_data post键值对数据
     * @return string
     */
    public function send_post($url, $post_data)
    {
        $postdata = http_build_query($post_data);
        $options = array(
            'http' => array(
                'method' => 'POST',
                'header' => 'Content-type:application/x-www-form-urlencoded',
                'content' => $postdata,
                'timeout' => 15 * 60 // 超时时间（单位:s）
            )
        );
        $context = stream_context_create($options);
        $result = file_get_contents($url, false, $context);
        return $result;
    }

}